/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.dataaccess.dao.review;

import com.nus.constant.ConstantBoolean;
import com.nus.constant.ConstantStatus;
import com.nus.dataaccess.dao.base.BaseEntity;
import com.nus.dataaccess.dao.conference.ConferenceAuthor;
import com.nus.dataaccess.dao.user.UserAccount;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author robin.foe
 */

@Entity
@Table(name="REVIEW_ASSIGNMENT")
public class ReviewAssignment extends BaseEntity {
    
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    public Long getId() {return id;}
    public void setId(Long id) {this.id = id;}
    @Override
    public Serializable getPk() {return this.getId();}
    
    @Column(name="CONFERENCE_AUTHOR_ID")
    private Long conferenceAuthorId;
    public Long getConferenceAuthorId() {return conferenceAuthorId;}
    public void setConferenceAuthorId(Long conferenceAuthorId) {this.conferenceAuthorId = conferenceAuthorId;}
    
    @Column(name="TITLE")
    private String title;
    public String getTitle() {return title;}
    public void setTitle(String title) {this.title = title;}
    
    @Column(name="DESCRIPTION")
    private String description;
    public String getDescription() {return description;}
    public void setDescription(String description) {this.description = description;}
            
    @Column(name="TOTAL_WEIGHT")
    private Integer totalWeight = 50;
    public Integer getTotalWeight() {return totalWeight;}
    public void setTotalWeight(Integer totalWeight) {this.totalWeight = totalWeight;}
    
    @Column(name="REVIEWER_ID")
    private Long reviewerId;
    public Long getReviewerId() {return reviewerId;}
    public void setReviewerId(Long reviewerId) {this.reviewerId = reviewerId;}
    
    @Column(name="BLIND_REVIEW", length=1, columnDefinition="CHAR(1)")
    private String blindReview = ConstantBoolean.NO;
    public boolean isBlindReview(){return ConstantBoolean.YES.equals(this.blindReview);}
    public void setBlindReview(boolean blindReview){ this.blindReview = (blindReview) ?ConstantBoolean.YES : ConstantBoolean.NO; }
    
    @Column(name="REVIEW_STATUS", length=1, columnDefinition="CHAR(1)")
    private String reviewStatus = ConstantStatus.REV_STS_PENDING;
    public String getReviewStatus() {return reviewStatus;}
    public void setReviewStatus(String reviewStatus) {this.reviewStatus = reviewStatus;}
   
    @ManyToOne
    @JoinColumn(name="CONFERENCE_AUTHOR_ID", referencedColumnName="ID",insertable=false,updatable=false)
    private ConferenceAuthor conferenceAuthor;
    public ConferenceAuthor getConferenceAuthor() {return conferenceAuthor;}
    public void setConferenceAuthor(ConferenceAuthor conferenceAuthor) {
        this.conferenceAuthor = conferenceAuthor;
        this.setConferenceAuthorId((conferenceAuthor == null) ? null : conferenceAuthor.getId());
    }
        
    @ManyToOne
    @JoinColumn(name="REVIEWER_ID", referencedColumnName="ID",insertable=false,updatable=false)
    private UserAccount reviewer;
    public UserAccount getReviewer() {return reviewer;}
    public void setReviewer(UserAccount reviewer) {
        this.reviewer = reviewer;
        this.setReviewerId((reviewer == null) ? null : reviewer.getId());
    }

    @OneToMany(mappedBy="reviewAssignment")
    private List<ReviewResult> reviewResults = new ArrayList<ReviewResult>();
    public List<ReviewResult> getReviewResults() {return reviewResults;}
    public void setReviewResults(List<ReviewResult> reviewResults) {this.reviewResults = reviewResults;}
    public ReviewResult getReviewResult(){
        return (reviewResults.isEmpty()) ? null : reviewResults.get(0);
    }
    
    
    /********************** Utility ************************/
    public boolean isCompleted(){return ConstantStatus.REV_STS_COMPLETED.equals(reviewStatus);}
    public boolean isPending(){return ConstantStatus.REV_STS_PENDING.equals(reviewStatus);}
    public boolean isInProgress(){return ConstantStatus.REV_STS_INPROGRESS.equals(reviewStatus);}
    
    public Integer getTotalScore(){
        return (this.getReviewResult() == null) ? 0 : this.getReviewResult().getTotalScore();
    }
    
    public Integer getTotalQrScore(){
        return (this.getReviewResult() == null) ? 0 : this.getReviewResult().getTotalQrScore();
    }
    
    public Integer getTotalEvScore(){
        return (this.getReviewResult() == null) ? 0 : this.getReviewResult().getTotalEvScore();
    }
    
    public Integer getTotalQwScore(){
        return (this.getReviewResult() == null) ? 0 : this.getReviewResult().getTotalQwScore();
    }
    
    public String getReviewerRemark01(){
        return (this.getReviewResult() == null) ? "" : this.getReviewResult().getRemark01();
    }
    
    public String getReviewerRemark02(){
        return (this.getReviewResult() == null) ? "" : this.getReviewResult().getRemark02();
    }
    
}
